<template>
  <div>
    <el-row type="flex" justify="end">
      <el-select v-model="curremtYear" size="mini" @change="dateChange">
        <el-option v-for="year in yearList" :key="year" :value="year" :label="`${year} 年`" />
      </el-select>
      <el-select v-model="currentMonth" size="mini">
        <el-option v-for="month in 12" :key="month" :value="month" :label="`${month} 月`" />
      </el-select>
    </el-row>
    <el-calendar v-model="currentDate">
      <template #dateCell="obj" class="content">
        <div class="date-content">
          <span class="text"> {{ obj.data.day | getDay }}</span>
          <span v-if="isWeek(obj.date)" class="rest">休</span>
        </div>
      </template>
    </el-calendar>
  </div>
</template>

<script>
export default {
  filters: {
    getDay(oldVal) {
      const str = oldVal.split('-')[2]
      return str.startsWith('0') ? str.substring(1) : str
    }
  },
  data() {
    const currentDate = new Date()
    const curremtYear = currentDate.getFullYear()
    const currentMonth = currentDate.getMonth() + 1
    const yearList = []
    for (let index = 0; index < 11; index++) {
      const yearStart = curremtYear - 5
      yearList.push(yearStart + index)
    }
    return {
      currentDate,
      curremtYear,
      currentMonth,
      yearList
    }
  },
  watch: {
    currentDate() {
      this.curremtYear = this.curremtYear.getFullYear()
      this.currentMonth = this.currentDate.getMonth() + 1
    }
  },
  methods: {
    dateChange() {
      this.currentDate = new Date(`${this.curremtYear}-${this.currentMonth}`)
    },
    isWeek(value) {
      return value.getDay() === 6 || value.getDay() === 0
    }
  }
}
</script>

<style  scoped>
::v-deep .el-calendar-day {
  height:  auto;
 }
 ::v-deep .el-calendar-table__row td,::v-deep .el-calendar-table tr td:first-child,  ::v-deep .el-calendar-table__row td.prev{
  border:none;
 }
.date-content {
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-size: 14px;
}
.date-content .rest {
  color: #fff;
  border-radius: 50%;
  background: rgb(250, 124, 77);
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
  font-size: 12px;
  margin-left: 10px;
}
.date-content .text{
  width: 20px;
  height: 20px;
  line-height: 20px;
 display: inline-block;

}
 ::v-deep .el-calendar-table td.is-selected .text{
   background: #409eff;
   color: #fff;
   border-radius: 50%;
 }
 ::v-deep .el-calendar__header {
   display: none
 }
</style>
